import threading
from datetime import datetime
import uuid

__timeid = dict()

def setTimeout(fun,s=0):
    s=s/1000
    timeout = threading.Timer(s,function= fun)
    timeout.start()
    key = str(uuid.uuid4()) + str(datetime.utcnow().timestamp())
    __timeid.setdefault(key,timeout)
    return key

def setInterval(fun,s=0):
    key = str(uuid.uuid4()) + str(datetime.utcnow().timestamp())
    s=s/1000
    def run():
        fun()
        timeout = threading.Timer(s,function= run)
        timeout.start()
        __timeid.setdefault(key,timeout)
    timeout = threading.Timer(s,function= run)
    timeout.start()
    __timeid.setdefault(key,timeout)
    return key

def clearTimeout(id):
    timeout:threading.Timer = __timeid.get(id)
    timeout.cancel()
    

def clearInterval(id):
    clearTimeout(id)